package com.golang.common.dto;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 接口响应体
 */
public class ResponseParam<T> {

    private ResponseHeader header;

    private T body;


    public ResponseParam() {
    }

    public ResponseParam(ResponseHeader header) {
        this.header = header;
    }

    public ResponseParam(ResponseHeader header, T body) {
        this.header = header;
        this.body = body;
    }

    public ResponseHeader getHeader() {
        return header;
    }

    public void setHeader(ResponseHeader header) {
        this.header = header;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }

    public String toString(){
        ObjectMapper mapper = new ObjectMapper();
        try {
            String jsonString = mapper.writeValueAsString(this);
            return jsonString;
        } catch (JsonProcessingException e) {
            return null;
        }
    }
}
